home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / PRIMITIV / SPHR / SPHRDLL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  2.9 KB  |  101 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /* $Id: SphrDll.cpp 1.2 1996/07/23 21:41:01 Damien Exp $ */ 
  3.  
  4. ////////////////////////////////////////////////////////////////////////
  5. //   Geometric Primitive Example : Sphere                             //
  6. //--------------------------------------------------------------------//
  7. //   DLL Management                                                   //
  8. ////////////////////////////////////////////////////////////////////////   
  9.  
  10.  
  11. #ifndef __SPHEDLL__
  12. #include "SPHRdll.h"
  13. #endif
  14.  
  15. #ifndef __SPHRFAC__
  16. #include "SPHRFac.h"
  17. #endif
  18.  
  19. #ifndef __COMSPHR__
  20. #include "COMSPHR.h"
  21. #endif
  22.  
  23. #ifndef __3DCOFAIL__
  24. #include "3DCoFail.h"
  25. #endif
  26.  
  27. STDAPI DllInitRDCom(IShUtilities* shellUtilities) {
  28.     InitCoFailure(shellUtilities);
  29.     return S_OK;
  30.     }
  31.  
  32. //------------------------------------------------------------------------
  33. /*
  34.  * DllGetClassObject
  35.  *
  36.  * This function gives a IClassFactory with the appropriate CLSID.
  37.  * This DLL must be in the registration database as a InProcServer
  38.  * for the correct CLSID
  39.  *
  40.  * Parameters:
  41.  *  clsID           REFCLSID that identifies the class factory
  42.  *                  desired.  Since this parameter is passed this
  43.  *                  DLL can handle any number of objects simply
  44.  *                  by returning different class factories here
  45.  *                  for different CLSIDs.
  46.  *
  47.  *  riid            REFIID specifying the interface the caller wants
  48.  *                  on the class object, usually IID_ClassFactory.
  49.  *
  50.  *  ppv             LPVOID FAR* in which to return the interface
  51.  *                  pointer.
  52.  *
  53.  * Returns NOERROR on success, otherwise an error code
  54.  */
  55.  
  56. STDAPI DllGetClassObject(REFCLSID rclsid
  57.     , REFIID riid, LPVOID FAR* ppv) {
  58.   if (!IsEqualCLSID(rclsid, CLSID_Sphere))
  59.       return ResultFromScode(E_FAIL);
  60.  
  61.   //Check that we can provide the interface
  62.   if (!IsEqualIID(riid, IID_IUnknown) && !IsEqualIID(riid, IID_IClassFactory))
  63.       return ResultFromScode(E_NOINTERFACE);
  64.  
  65.   //Return our IClassFactory for the correct objects
  66.   if (IsEqualCLSID(rclsid,CLSID_Sphere))
  67.     *ppv=(LPVOID) new SphereClassFactory();
  68.  
  69.   if (*ppv == NULL)
  70.       return ResultFromScode(E_OUTOFMEMORY);
  71.  
  72.   //AddRef the object through any interface we return
  73.   ((LPUNKNOWN)*ppv)->AddRef();
  74.  
  75.   return NOERROR;
  76.   }
  77.  
  78.  
  79. /*
  80.  * DllCanUnloadNow
  81.  *
  82.  *  Answers if the DLL can be unload from the memory
  83.  *
  84.  *  This function doesn't need any parameter
  85.  *
  86.  *  Returns TRUE if nothing is using us, FALSE otherwise.
  87.  */
  88.  
  89. STDAPI DllCanUnloadNow() {
  90.   SCODE   sc;
  91.  
  92.   //Our answer is whether there are any object or locks
  93.   sc=(0L==global_count_Obj && 0L==global_count_Lock) ? S_OK : S_FALSE;
  94.   return ResultFromScode(sc);
  95.   }
  96.  
  97. //------------------------------------------------------------------------
  98. //Count number of objects and number of locks.
  99. long       global_count_Obj  = 0;
  100. long       global_count_Lock = 0;
  101.